package system

import (
	"github.com/astaxie/beego/toolbox"
	"github.com/rcrowley/go-metrics"
	"github.com/shirou/gopsutil/host"
)

var (
	StatusError error
	Register    metrics.Registry
)

func init() {
	Register = metrics.NewRegistry()
	tk := toolbox.NewTask("GetUptimeTask", "*/1 * * * * *", GetUptimeTask)
	toolbox.AddTask("GetUptimeTask", tk)
}

func GetUptimeTask() error {
	uptime, err := host.Uptime()
	if err != nil {
		StatusError = err
		return err
	}
	M := metrics.GetOrRegisterGauge("uptime", Register)
	M.Update(int64(uptime))
	return nil
}
